import Taro from '@tarojs/taro';
/**
 * 访问接口
 * @param {*} url 接口地址
 * @param {*} data 接口上传的参数
 * @param {*} method 方式
 */
export const Request = (url,data={},method="POST",header={"content-type":"application/json"}) => {
    return new Promise((resolve, reject)=>{
        Taro.request({
            url:url,
            data:data,
            method:method,
            header:header,
            success:function(res){
                resolve(res);
            },
            fail:function(res){
                reject(res);
            }
        })
    })
}

export const globalData = {}

export function setGlobalData (key, val) {
  globalData.key = val
}
export function getGlobalData (key) {
  return globalData.key
}

//获取某月的天数
export function getMonthDay(year,month){
    var date = new Date(year,month,0);
    return date.getDate();
}

export function weekNumToText(weekNum){
    switch(weekNum){
        case 0:
            return "周日";
        case 1:
            return "周一";
        case 2:
            return "周二";
        case 3:
            return "周三";
        case 4:
            return "周四";
        case 5:
            return "周五";
        case 6:
            return "周六";
        default:
            return "error";
    }
}

export function combineDate(year,month,day){
    var fmt_month;
    var fmt_day;
    if(month<10){
        fmt_month = "0" + month;
    }else{
        fmt_month = month
    }

    if(day<10){
        fmt_day = "0" + day;
    }else{
        fmt_day = day;
    }

    let fmt_date = year+"/"+fmt_month+"/"+fmt_day;

    return fmt_date;


}